<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
	<link rel="stylesheet" href="__static/css/public.css" media="all">
	<style>
		.layui-form-pane .layui-form-label {
			width: 90px;
		}
	</style>
</head>
<body>
<div class="layuimini-container"> 
	<div class="layuimini-main">
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-success layui-btn-sm data-add-btn" lay-event="add_order">添加群聊</button>
			</div>
		</script>
		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
		<script type="text/html" id="currentTableBar">
			<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="save">修改</a>
			<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
			
		</script>
	</div>
</div>
<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="__static/js/man.js" charset="utf-8"></script>
<script>
//添加群聊
function add_order(){
	layer.open({
        type: 2,
        title:'添加群聊',
        area: ['60%', '70%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('add_group')}"
    });
    //layer.full(index);
}
// 修改
function get_save(id){
	layer.open({
        type: 2,
        title:'修改群聊',
        area: ['60%', '70%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('save_group')}?id=" + id
    });
}

	var $,form,table,laydate
	layui.use(['form', 'table', 'tableSelect', 'laydate'], function () {
		$ = layui.jquery , form = layui.form , table = layui.table , laydate = layui.laydate
		 laydate.render({
			    elem: '#date', //指定元素
			  });
		
		table.render({
			elem: '#currentTableId',
			id:'items_list',
			url: '{:url("index")}?t=json',
			height: 'full-150',
			method : 'post',
			toolbar: '#toolbarDemo',
			cols: [[
				{ field: 'name', title: '群名称'},
				{ field: 'channel_names', title: '绑定端口'},
			    { field: 'media_name', title: '媒介'},
			    { field: 'create_time', title: '创建日期'},
			    { title: '操作', minWidth: 150, fixed: 'right', toolbar: '#currentTableBar',align:'center'}
			]]
			
		});
		 
		/**
		 * toolbar监听事件
		 */
		table.on('toolbar(currentTableFilter)', function (obj) {
			switch (obj.event) {
				case 'add_order':
					add_order();
				break;
			}
			
		});
		table.on('tool(currentTableFilter)', function (obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'save':
					get_save(data.id);
				break;
				case 'delete':
					layer.confirm('您确认要删除此群聊吗？', {
		                btn: ['确认', '取消'] //按钮
		            }, function () {
		            	layer.load(1, { shade : [ 0.5, '#676a6c' ] }); 
						$.post("{:url('del_group')}?t=json",{id:data.id},function(da){
							layer.closeAll();
							if(da['code'] == 1){
								obj.del(); 
								layer.msg(da['msg'], {icon: 6});
							}else{
							 layer.msg(da['msg'], { icon : 5 });
							}
						});
		            });
					
					
				break;
			}
		});
		

	});
	function get_load(msg){
		table.reload('items_list', {
			  url: '{:url("index")}?t=json',
			});
		layer.msg(msg, {icon: 6});
	}
	
</script>

</body>
</html>